<!DOCTYPE html>
<html>
{include file="users/public_layout" /}
<body>
<div class="layui-fluid " id="LAY-component-layer-list">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body layui-form house-form" wid100>
                    <div class="layui-form-item"></div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">原密码</label>
                        <div class="layui-input-inline">
                            <input type="password" width="100" type="text" name="oldpassword" value="" class="layui-input" placeholder="请输入原密码" >
                        </div>
                        <div class="layui-input-inline line-h38">
                            
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">新密码</label>
                        <div class="layui-input-inline">
                            <input type="password" type="text" id="password" name="password" value="" class="layui-input" placeholder="密码至少6位" >
                        </div>
                        <div class="layui-input-inline line-h38">
                            
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">确认密码</label>
                        <div class="layui-input-inline">
                            <input type="password" type="text" id="password2" name="password2" value="" class="layui-input" placeholder="再次输入确认">
                        </div>
                        <div class="layui-input-inline line-h38">
                            <span id="pass_span" style="color:red;"></span>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $("#password2").keyup(function(){
        var password = $("#password").val();
        var password2 = $("#password2").val();
        if (password == password2){
            $("#pass_span").html("");
        }else {
            $("#pass_span").html("两次密码输入不一致");
        }

    });
    layui.config({
        base: '__SKIN__/' //静态资源所在路径
        ,version: '{$version}'
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form',  'upload'], function(){
        var $ = layui.$
            ,upload = layui.upload
            ,form = layui.form;

        //监听提交
        form.on('submit(formSubmit)', function(data){
            var password = $("#password").val();
            var password2 = $("#password2").val();
            if (password !== password2){
                layer.msg("两次密码输入不一致，请重新输入", {icon: 2,time: 2000});
                return false;
            }
            var load = layer_loading();
            data.field._ajax = 1;
            $.ajax({
                type : 'post',
                url : "{:url('Users/pwd')}",
                data : data.field,
                dataType : 'json',
                success : function(res){
                    layer.close(load); //关闭loading
                    if(res.code == 1){
                        layer.msg(res.msg, {icon: 1,time: 2000});
                    }else{
                        layer.msg(res.msg, {icon: 2,time: 2000});
                    }
                },
                error: function(e){
                    layer.close(load); //关闭loading
                    showErrorAlert();
                }
            });
            return false;
        });

    });
</script>

</body>
</html>